<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获取国家代码</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.geoip-continent-code-by-name.html">« geoip_continent_code_by_name</a></li>
      <li style="float: right;"><a href="function.geoip-country-code3-by-name.html">geoip_country_code3_by_name »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.geoip.html">GeoIP 函数</a></li>
    <li>获取国家代码</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.geoip-country-code-by-name" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">geoip_country_code_by_name</h1>
  <p class="verinfo">(PECL geoip &gt;= 0.2.0)</p><p class="refpurpose"><span class="refname">geoip_country_code_by_name</span> &mdash; <span class="dc-title">获取国家代码</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.geoip-country-code-by-name-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>geoip_country_code_by_name</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$hostname</code></span>): <span class="type">string</span></div>


  <p class="para rdfs-comment">
    <span class="function"><strong>geoip_country_code_by_name()</strong></span> 函数将会返回主机或者IP地址所在的国家代码。
  </p>

 </div>

 <div class="refsect1 parameters" id="refsect1-function.geoip-country-code-by-name-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">hostname</code></dt>

     <dd>

      <p class="para">
       定位的主机名或者IP地址。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.geoip-country-code-by-name-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功，返回 ISO 定义的国家代码，如果在数据库中未找到相关信息则返回 <strong><code>false</code></strong> 。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.geoip-country-code-by-name-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3379">
    <p><strong>示例 #1  <span class="function"><strong>geoip_country_code_by_name()</strong></span> 函数的范例：</strong></p>
    <div class="example-contents"><p>
     以下代码将会打印 example.com 主机的定位信息。
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$country&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">geoip_country_code_by_name</span><span style="color: #007700">(</span><span style="color: #DD0000">'www.example.com'</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">$country</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'This&nbsp;host&nbsp;is&nbsp;located&nbsp;in:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$country</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
This host is located in: US
</pre></div>
    </div>
   </div>
  </p>
 </div>

 
 <div class="refsect1 notes" id="refsect1-function.geoip-country-code-by-name-notes">
  <h3 class="title">注释</h3>
  <div class="caution"><strong class="caution">警告</strong>
   <p class="para">
    请点击 <a href="http://www.maxmind.com/en/iso3166" class="link external">&raquo;&nbsp;http://www.maxmind.com/en/iso3166</a> 来查看所有可能的返回值列表，包括特殊代码。
   </p>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.geoip-country-code-by-name-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.geoip-country-code3-by-name.html" class="function" rel="rdfs-seeAlso">geoip_country_code3_by_name()</a> - 获取三个字母组成的国家简称</span></li>
    <li class="member"><span class="function"><a href="function.geoip-country-name-by-name.html" class="function" rel="rdfs-seeAlso">geoip_country_name_by_name()</a> - 获取国家的全称</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>